home *** CD-ROM | disk | FTP | other *** search
/ The World of Computer Software / The World of Computer Software.iso / vim_src.zip / MKCMDTAB.C < prev    next >
C/C++ Source or Header  |  1993-01-12  |  2KB  |  112 lines

  1. /* vi:ts=4:sw=4
  2.  *
  3.  * VIM - Vi IMitation
  4.  *
  5.  * Code Contributions By:    Bram Moolenaar            mool@oce.nl
  6.  *                            Tim Thompson            twitch!tjt
  7.  *                            Tony Andrews            onecom!wldrdg!tony 
  8.  *                            G. R. (Fred) Walter        watmath!watcgl!grwalter 
  9.  */
  10.  
  11. /*
  12.  * mkcmdtab.c: separate program that reads cmdtab.tab and produces cmdtab.h
  13.  *
  14.  *    call with: mkcmdtab cmdtab.tab cmdtab.h
  15.  */
  16.  
  17. #include <stdlib.h>
  18. #include <stdio.h>
  19. #include "vim.h"
  20.  
  21.     void
  22. main(argc, argv)
  23.     int        argc;
  24.     char    **argv;
  25. {
  26.     register int    c;
  27.     char            buffer[100];
  28.     int                count;
  29.     int                i;
  30.     FILE            *ifp, *ofp;
  31.  
  32.     if (argc != 3)
  33.     {
  34.         fprintf(stderr, "Usage: mkcmdtab cmdtab.tab cmdtab.h\n");
  35.         exit(10);
  36.     }
  37.     ifp = fopen(argv[1], "r");
  38.     if (ifp == NULL)
  39.     {
  40.         perror(argv[1]);
  41.         exit(10);
  42.     }
  43.     ofp = fopen(argv[2], "w");
  44.     if (ofp == NULL)
  45.     {
  46.         perror(argv[2]);
  47.         exit(10);
  48.     }
  49.  
  50.     while ((c = getc(ifp)) != '|' && c != EOF)
  51.         putc(c, ofp);
  52.     fprintf(ofp, "THIS FILE IS AUTOMATICALLY PRODUCED - DO NOT EDIT");
  53.     while ((c = getc(ifp)) != '|' && c != EOF)
  54.         ;
  55.     while ((c = getc(ifp)) != '|' && c != EOF)
  56.         putc(c, ofp);
  57.  
  58.     count = 0;
  59.     while ((c = getc(ifp)) != '|' && c != EOF)
  60.     {
  61.         putc(c, ofp);
  62.         while ((c = getc(ifp)) != '"' && c != EOF)
  63.             putc(c, ofp);
  64.         putc(c, ofp);
  65.  
  66.         i = 0;
  67.         while ((c = getc(ifp)) != '"' && c != EOF)
  68.         {
  69.             putc(c, ofp);
  70.             buffer[i++] = c;
  71.         }
  72.         putc(c, ofp);
  73.         buffer[i] = 0;
  74.  
  75.         while ((c = getc(ifp)) != '\n' && c != EOF)
  76.             putc(c, ofp);
  77.         putc(c, ofp);
  78.  
  79.         switch (buffer[0])
  80.         {
  81.             case '@':    strcpy(buffer, "at");
  82.                         break;
  83.             case '!':    strcpy(buffer, "bang");
  84.                         break;
  85.             case '<':    strcpy(buffer, "lshift");
  86.                         break;
  87.             case '>':    strcpy(buffer, "rshift");
  88.                         break;
  89.             case '=':    strcpy(buffer, "equal");
  90.                         break;
  91.             case '&':    strcpy(buffer, "and");
  92.                         break;
  93.             case '~':    strcpy(buffer, "tilde");
  94.                         break;
  95.         }
  96.                     
  97.         fprintf(ofp, "#define CMD_%s %d\n", buffer, count++);
  98.     }
  99.  
  100.     fprintf(ofp, "#define CMD_SIZE %d\n", count);
  101.  
  102.     while ((c = getc(ifp)) != '|' && c != EOF)
  103.         putc(c, ofp);
  104.  
  105.     if (c != '|')
  106.     {
  107.         fprintf(stderr, "not enough |'s\n");
  108.         exit(1);
  109.     }
  110.     exit(0);
  111. }
  112.